//
//  NetworkConfig.h
//  ServiceCode
//
//  Created by 曹连华 on 2020/3/27.
//

#import <Foundation/Foundation.h>
#import <BaseCode/BaseCode.h>
NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, ENetworkError){
    kLaunchFail = 1,                           //启动接口调用失败
    kLoginFailWhenTokenExpire,                  //启动接口调用失败
    kGetSignKeyFailWhenSignKeyExpire,           //密钥过期后重新获取密钥失败
    kReturnCodeNotEqualToZero,                 //rtn_code不为0
    kDataTypeMismatch,                         // 数据类型不匹配
    kChangeIpForServerError,                   //服务器5xx错误后更换ip后仍然失败
    kSessionInvalid,                           //session无效
    kNotConnectToServer = -1004,               //网络连接错误
    kServerError = -1011,                      //服务器错误
};

#define ShowNetworkErrorNotification @"ShowNetworkErrorNotification" //显示错误界面(无网络连接，或者服务器忙)
#define HideNetworkErrorNotification @"HideNetworkErrorNotification" //隐藏无网络错误界面
#define NetworkInterfaceReturnErrorDomain @"NetworkInterfaceReturnErrorDomain" //隐藏无网络错误界面
#define NetworkMaxAllowedHTTPSFailedTimes 5

@interface NetworkDomainModel : BaseValueObject

@property (nonatomic, strong) NSString *networkTitle;
@property (nonatomic, strong) NSString *networkDomain;
@property (nonatomic, strong) NSString *securedDomain;
@property (nonatomic, strong) NSString *netWorkH5Domain;
@property (nonatomic, strong) NSString *securedH5Domain;

+ (NetworkDomainModel *)modelTitle:(NSString *)title
                     networkDomain:(NSString *)networkDomain
                     securedDomain:(NSString *)securedDomain;

+ (NetworkDomainModel *)modelTitle:(NSString *)title
                     networkDomain:(NSString *)networkDomain
                     securedDomain:(NSString *)securedDomain
                   netWorkH5Domain:(NSString *)netWorkH5Domain
                   securedH5Domain:(NSString *)securedH5Domain;
@end

#define PB_HTTPS_SWITCHED_NOTIFICATION     @"PB_HTTPS_SWITCHED_NOTIFICATION"

@interface NetworkConfig : BaseValueObject

@property (nonatomic, strong, readonly) NetworkDomainModel *onlineNetworkDomain;
@property (nonatomic, strong, readonly) NetworkDomainModel *currentNetworkDomain;

/**
 * 强制应用 http 接口 defout NO
 */
@property (nonatomic, getter = isForceHttp, assign)BOOL forceHttp;

/**
 * 接口是否用 HTTPS defout NO
 */
@property (nonatomic, getter = isUseHTTPSForVenus, assign)BOOL useHTTPSForVenus;

/**
 * H5 站点是否用 HTTPS defout NO
 */
@property (nonatomic, getter = isUseHTTPSForH5, assign)BOOL useHTTPSForH5;

/**
 * Interface接口是否用 HTTPS  defout NO
 */
@property (nonatomic, getter = isUseHTTPSForInterface, assign)BOOL useHTTPSForInterface;
/**
 * HTTPS 白名单 defout @[]
 */
@property (nonatomic, strong) NSArray *httpsWhiteList;
/**
 * 客户端app版本号
 */
@property (nonatomic, copy) NSString *appVersion;
/**
 * 客户端系统
*/
@property (nonatomic, copy) NSString *clientSystem;
/**
 * 客户端版本
*/
@property (nonatomic, copy) NSString *systemVersion;
/**
 * 设备号
*/
@property (nonatomic, copy) NSString *deviceCode;
/**
 * 平台名称 eg : iosSystem  iPadSystem
*/
@property (nonatomic, copy) NSString *traderName;
/**
 * 纬度
*/
@property (nonatomic, copy) NSNumber *latitude;
/**
 * 经度
*/
@property (nonatomic, copy) NSNumber *longitude;

/**
 * ip
*/
@property (nonatomic, copy)   NSString *ip;
/**
 * 用户token
 */
@property (nonatomic, copy)   NSString *token;

/**
 *  服务器时间-客户端时间(时间差值)
 */
@property (nonatomic, assign) NSTimeInterval dTime;

/**
 *  根据差值算出的服务器时间
 */
@property (nonatomic, copy)   NSDate *serverTime;

/**
 *  网络类型
*/
@property (nonatomic, copy)   NSString *nettype;

/**
 *  地址信息
*/
@property (nonatomic, copy)   NSDictionary *addressInfo;
/**
 *  解密后的签名密钥
 */
@property (nonatomic, copy) NSString *signatureKey;


/*
 * 根据差值算出的服务器时间戳
 */
- (NSString *)serverTimestamp;

/**
 * 功能:获取签名字符串
 */
- (NSString *)getSignature:(NSDictionary *)aDict;

/**
 *  功能:获取AES加密的token
 */
- (NSString *)getAesEncodedToken;

+ (NetworkConfig *)sharedInstance;

/**
*  配置线上网络环境和测试网络环境
*  eg：[[NetworkConfig  sharedInstance]setOnlineNetworkDomain:[NetworkDomainModel modelTitle:@"线上环境" networkDomain:@"http://xxx.com"       securedDomain:@"http://xxx.com"]];
*/
- (void)setOnlineNetworkDomain:(NetworkDomainModel *)onlineNetworkDomain;

/**
 *  配置线上网络环境和测试网络环境
 *  eg：[[NetworkConfig  sharedInstance]setNetworkDomains:@[NetworkDomainModel modelTitle:@"线上环境" networkDomain:@"http://xxx.com" securedDomain:@"http://xxx.com"],][NetworkDomainModel modelTitle:@"测试环境" networkDomain:@"http://xxx.com" securedDomain:@"http://xxx.com"];
 */
- (void)setNetworkDomains:(NSArray<NetworkDomainModel *>*)domains;

/**
 * 切换网络环境
 */
- (void)switchNetworkDomain;

@end

NS_ASSUME_NONNULL_END
